﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

class UISelect:BaseUI
{
    public Image id1;
    public Image id2;
    public Image id3;
    public Image id4;
    public Image id5;
    public Image id6;
    public Image id7;
    public Image id8;
    public Image id9;
    public override void BindCompotent(string imgName,GameObject go)
    {
        switch (imgName)
        {
            case "Image1":
                Debug.Log(imgName);
                id1 = go.GetComponent<Image>();
                IsActive(id1, 1);
                    break;
            case "Image2":
                id2 = go.GetComponent<Image>();
                IsActive(id2, 2);
                break;
            case "Image3":
                id3 = go.GetComponent<Image>();
                IsActive(id3, 3);
                break;
            case "Image4":
                id4 = go.GetComponent<Image>();
                IsActive(id4, 4);
                break;
            case "Image5":
                id5 = go.GetComponent<Image>();
                IsActive(id5, 5);
                break;
            case "Image6":
                id6 = go.GetComponent<Image>();
                IsActive(id6,6);
                break;
            case "Image7":
                id7 = go.GetComponent<Image>();
                IsActive(id7, 7);
                break;
            case "Image8":
                id8 = go.GetComponent<Image>();
                IsActive(id8, 8);
                break;
            case "Image9":
                id9 = go.GetComponent<Image>();
                IsActive(id9, 9);
                break;
            default:
                break;
        }
    }
    public override void OnButtonClick(string btnName)
    {
        switch (btnName)
        {
            case "BtnLevel1":
                InitBattle(1);
                break;
            case "BtnLevel2":
                InitBattle(2);
                break;
            case "BtnLevel3":
                InitBattle(3);
                break;
            case "BtnLevel4":
                InitBattle(4);
                break;
            case "BtnLevel5":
                InitBattle(5);
                break;
            case "BtnLevel6":
                InitBattle(6);
                break;
            case "BtnLevel7":
                InitBattle(7);
                break;
            case "BtnLevel8":
                InitBattle(8);
                break;
            case "BtnLevel9":
                InitBattle(9);
                break;
            case "BtnReset":
                Saver.SetProgress(1);
                UIManager.EnterUI<UISelect>();
                UIManager.ExitUI(this);
                break;
            case "Reback":
                var s=UIManager.EnterUI<UIMain>();
                s.LoadInit();
                UIManager.ExitUI(this);
                break;
            default:
                break;
        }
    }

    //辅助方法
    void IsActive(Image img,int id)
    {
        if(id<= Saver.GetProgress())
        {
            img.enabled = false;
        }
        else
        {
            img.enabled = true;
        }
    }
    //初始化场景
    void InitBattle(int id)
    {
        GameMain.Instance.currentProgress = id;
        var t= UIManager.EnterUI<UIBattle>();
        t.LoadInit(id.ToString());
        UIManager.ExitUI(this);
    }
}